//#define __FORCE_TRACE__
//#define __FORCE_DEBUG__
//#define __FORCE_INFO__
#define THIS_FILE "server\fn_serverExecuteEjectPassanger.sqf"
#include <tmf_constants.h>
#include <tmf_macros.h>

TRACE_1("Start",_this);
TMFPROFILERSTART;

private ["_vec","_crew"];
DEFAULT_PARAM(_vec,0,objNull);

if (!isnull _vec) then {
	{
		_crew = _x;
		if (vehicle _crew == _vec && _crew != driver _vec && local _crew) then {
			_crew allowDamage false;
			TRACE_1("Ejecting",ARR_2(_crew,typeof _crew));
			unassignVehicle _crew;
			_crew leaveVehicle _vec;
			// _crew setVelocity [0,0,0];
			[_crew,_vec] spawn {
				private ["_crew","_vec","_pos"];
				_crew = _this select 0;
				_vec = _this select 1;
				if (vehicle _crew != _crew) then {
					_crew action ["eject", _vec];
				};
				sleep 0.3;
				_pos = getPos _vec;
				_pos set [2, (_pos select 2) - 10];
				_crew setPos _pos;
				// _crew setVelocity [0,0,0];
				_wait = time + 60;
				waituntil { _wait < time };
				_crew allowDamage true;
			};
		};
	} foreach crew _vec;
};

TRACE("End");
TMFPROFILERSTOP;